package com.thunder.reader.data;

import java.io.IOException;

import android.text.TextUtils;

import com.thunder.reader.ReaderBaseException;

/**
 * Use Http protocol to get the article specified by Url from QQ server
 * @author AM
 *
 */
public class ArticleGetter {
    private String mOriginalUrl;
    private static final String mQQServer = "http://mrss.3g.qq.com:8081/?scid=28&type=page";
    private String mArticleUrl;
    
    public ArticleGetter(String url) throws ReaderBaseException {
        if (TextUtils.isEmpty(url)) {
            throw new ReaderBaseException("invalid url its is empty, did you pass valid URL correctly?");
        }
        mOriginalUrl = url;
        mArticleUrl = mQQServer + "&url=" + url;
    }

    public String getOriginalUrl() throws ReaderBaseException {
        if (mOriginalUrl == null) {
            throw new ReaderBaseException("invalid original url, did you initialize this class correctly?");
        }
        return mOriginalUrl;
    }
    
    public String getArticleUrl() throws ReaderBaseException {
        if (mArticleUrl == null) {
            throw new ReaderBaseException("invalid article url, did you initialize this class correctly?");
        }
        return mArticleUrl;
    }
    
    public String getArticleContent() throws ReaderBaseException, IOException {
        if (mArticleUrl == null) {
            throw new ReaderBaseException("invalid article url, did you initialize this class correctly?");
        }
        
        return new UrlReader(mArticleUrl).getContentAsString();
    }
}
